<?php
set_time_limit(0);
$dbhost = '47.110.131.55';
$dbuser = 'root';
$dbpwd  ='sxy7788123456';
$dbName ='gu';
$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqliTwo->error);}
//http://mei94.com/si/set-ti/6.php
$nianji=6;
$query=$mysqli->query("select id,step,title,da,db,dc,dd,dan from ti where nianji='".$nianji."' ");
$tiAInfo=array();
while ($list=$query->fetch_array()){
    $tiAInfo[]=array('step'=>$list['step'],'id'=>$list['id'],'title'=>$list['title'],'da'=>$list['da'],'db'=>$list['db'],
        'dc'=>$list['dc'],'dd'=>$list['dd'],'dan'=>$list['dan']
    );
}
for ($j=1;$j<20;$j++){
    shuffle($tiAInfo);
    $list=array();
    $tiBInfo=array();
    $one_10=1;
    $two_10=1;
    $three_10=1;
   /**
    d)六年级（南通地区）：第一部分（1-40题选20题）；
    第二部分（41-120题选65题）；
    第三部分（121-180题选35题）
    */
    foreach ($tiAInfo as $list){
            $tiBInfo[]=array('id'=>$list['id'],'title'=>$list['title'],'da'=>$list['da'],'db'=>$list['db'],
                'dc'=>$list['dc'],'dd'=>$list['dd'],'dan'=>$list['dan']
            );
    }
    file_put_contents('../tiKu/'.$nianji.'-'.$j.'.txt', json_encode(array('a'=>$tiBInfo)));
    
}
echo $nianji;

$mysqli->close();